<script type="text/javascript"><!--//--><![CDATA[//><!--

    var grid_reload = function(){
        $('#datagrid').datagrid('reload', $('#fm_search').serializeObject());
    };

    $(document).ready(function() {
        // Setup Datagrid
        $('#datagrid').datagrid({  
            url:gs_path+'/'+controller+'/getdata', 
            queryParams: $('#fm_search').serializeObject(),
            height:520,
            pagination:true,
            columns:[[
  			    { field : 'ck', checkbox:true, width: 40, align: 'center' },
                { field : 'cost_centre', title : 'Cost Centre', width : 200, sortable:true },
                { field : 'jumlah_harga', title : 'Jumlah Harga', width : 100, sortable:true },
                { field : 'harga_satuan', title : 'Harga Satuan', width : 100, sortable:true },
				{ field : 'jumlah_satuan', title : 'Jumlah Satuan', width : 100, sortable:true },
                { field : 'keterangan', title : 'Keterangan', width : 550, sortable:true }
            ]]
        });
        
        
        // Setup Form
        $('#form_master').setupForm([
            { name: 'cost_centre', type: 'text', size: 'medium', maxlength: 100, noempty:true },
            { name: 'jumlah_harga', type: 'text', size: 'medium', maxlength: 100, noempty:true },
            { name: 'harga_satuan', type: 'text', size: 'medium', maxlength: 100, noempty:true },
            { name: 'jumlah_satuan', type: 'text', size: 'medium', maxlength: 100, noempty:true },
			{ name: 'keterangan',type:'textarea', size: 'long', maxlength: 250, noempty:true },
        ]);
        
        
        // Create Dialog
        $('#dialog_container').dialog({
            closed:true,
            modal:true,
            title: '_',
            width:600,
			height:500,
            buttons:[{
                text:'Save',
                iconCls:'icon-save',
                handler:function(){
                    $('#form_master').submitForm('/'+controller+'/ajax_post', { onComplete : function(){ $('#dialog_container').dialog('close'); $('#datagrid').datagrid('reload'); }} );
                }
            },{
                text:'Close',
                iconCls:'icon-cancel',
                handler:function(){
                    $('#dialog_container').dialog('close');
                }
            }]
        });
        
        // Set Action Button
        var buttons = [ { label: 'Add', icon: 'add', onclick: function() {
                            resetError();
                            $('#dialog_container').dialog('open');
                            $('#form_master').data('mode', 'create');
                            $('#form_master').parent().parent().parent().prev().find('.panel-title').html('Tambah Data Pertanggung Jawaban Uang Muka');
                            $('#cost_centre').readonly(false);
                            $('#cost_centre, #jumlah_harga, #harga_satuan, #jumlah_satuan, #keterangan').val('');
                            $('#kode_barang').focus();
                        } },
                        { label: 'Edit', icon: 'edit', onclick: function() {
                            var oSel=$('#datagrid').datagrid('getSelected'); 
                            if(oSel==null){ 
                                alert('Please select row!'); 
                            } else{ 
                                resetError();
                                $('#dialog_container').dialog('open'); 
                                $('#form_master').data('mode', 'edit');
                                $('#form_master').parent().parent().parent().prev().find('.panel-title').html('Edit Data Pertanggung Jawaban Uang Muka');
                                $('#cost_centre').readonly();
                                jsonToForm(oSel); 
                                $('#cost_centre').focus();
                            } 
                        } },
                        {label: 'Delete', icon: 'delete', onclick: function() { 
                            var oSel = $('#datagrid').datagrid('getSelected'); 
                            if (oSel == null) { 
                                $.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
                            } else { 
                                deleteData(['cost_centre']);
                            } 
                        }},
                        {label: 'Download', icon:'excel', onclick: function() { 
                            setLoading(true);
                            $.ajax({
                                type: 'POST', url: gs_path+'/'+controller+'/download/', cache: false, data: jQuery.param( $('#fm_search').serializeArray().concat({ name:'sessid', value:sessid })),
                                success: function(data) { setLoading(false); if(data!=''){ alert(data); return false; } document.getElementById('if_download').src='<?php echo base_url(); ?>app/download/?file=<?php echo _SESSID; ?>.xls&filename=download_data.xls'; },
                                error: function(xhr, ajaxOptions, thrownError) { setLoading(false); var ls_message = ''; var ls_logmessage = ''; if (xhr.status == 0) { ls_message = 'You are offline!!\n Please Check Your Network.'; } else if (xhr.status == 404) { ls_message = 'Requested URL not found.'; } else if (xhr.status == 500) { ls_message = 'Internal Server Error.';  } else if (thrownError == 'parsererror') { ls_message = 'Error.\nParsing JSON Request failed.' } else if (thrownError == 'timeout') { ls_message = 'Request Time out.'; } else { ls_message = 'Unknow Error.\n' + xhr.responseText; } $.messager.alert('&nbsp;',nl2br(ls_message),'error'); }, dataType: "html"
                            });
                        }}];
        setAction(buttons);
        
        
        $('#fm_search').focusFirst();
    });
//--><!]]></script>

<div id="tb" style="padding:5px;height:auto">
    <div>
        <form id="fm_search" onsubmit="grid_reload(); return false;">
            <table class="tb_form" style="margin-bottom:0px">
            <tr>
                <td width="100">Keyword</td>
                <td><input type="text" id="keyword" name="keyword" class="textfield medium" />
                    <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload(); return false;">Search</a>
                </td>
            </tr>
            </table>
        </form>
    </div>
</div>
<div id="datagrid" toolbar="#tb"></div>


<div id="dialog_container" style="padding:5px;width:600px;height:250px;">
    <form id="form_master">
    <table class="tb_form" style="width:100%;" cellpadding="0" cellspacing="0">
     <tr>
        <td class="label" style="width:150px">Cost Centre</td>
        <td><input id="cost_centre" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Jumlah Harga (RP)</td>
        <td><input id="jumlah_harga" /></td>
    </tr>
    <tr>
        <td class="label">Harga Satuan (RP)</td>
        <td><input id="harga_satuan" /></td>
    </tr>
    <tr>
        <td class="label">Jumlah Satuan</td>
        <td><input id="jumlah_satuan" /></td>
    </tr>
    <tr>
        <td class="label">Keterangan</td>
        <td><input id="keterangan" /></td>
    </tr>
    </table>
    </form>
</div>